<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>列表用户和角色关联表</title>
    <meta name="keywords" content="列表用户和角色关联表">
    <meta name="description" content="列表用户和角色关联表">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/hplus/css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="/hplus/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/hplus/css/animate.css" rel="stylesheet">
    <link href="/hplus/css/style.css?v=4.1.0" rel="stylesheet">


</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins  border rounded-lg">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <form role="form" class="form-inline">
                        <div class="form-group">
                            <label for="exampleInputEmail2" >用户名</label>
                            <input type="email" placeholder="请输入用户名" id="exampleInputEmail2" class="form-control">
                        </div>
                        <button type="button" class="btn btn-primary glyphicon glyphicon-search" onclick="$.table.search()">查询</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- Panel Other -->
    <div class="ibox float-e-margins border rounded-lg">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <div class="example">
                            <div class="btn-group hidden-xs" id="toolBar" role="group">
                                <button type="button" class="btn btn-outline btn-default" title="新增" onclick="add('新增','container');">
                                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                                </button>
                                <button type="button" class="btn btn-outline btn-default editAble" disabled title="编辑" onclick="edits('编辑','container');">
                                    <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>

                                </button>
                                <button type="button" class="btn btn-outline btn-default deleteAll" disabled title="删除" onclick="deletes();">
                                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                </button>
                            </div>
                            <table id="dataTable" data-height="400" data-mobile-responsive="true">
                            </table>
                        </div>
                    </div>
                    <!-- End Example Events -->
                </div>
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
    <div id="layerForm" style="display: none">
        <div class="ibox-content" style="margin-top: 10px;" id="container">
            <form id="mForm" class="form-horizontal" style="width:60%;margin-left:20%;">
                    <input type="hidden" v-model="entity.userId"/>

                            <div class="form-group">
                                <label class="control-label col-sm-3">
                                    角色ID
                                </label>
                                <div class="col-sm-7 pull-right" >
                                    <input v-model="entity.roleId" type="text"  class="form-control" name="roleId"  placeholder="角色ID">
                                </div>
                            </div>

            </form>
        </div>
    </div>
</div>

</body>
<!-- 全局js -->
<script src="/hplus/js/jquery.min.js?v=2.1.4"></script>
<script src="/hplus/js/bootstrap.min.js?v=3.3.7"></script>

<!-- 自定义js -->
<script src="/hplus/js/content.js?v=1.0.0"></script>


<!-- Bootstrap table -->
<script src="/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/hplus/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- layer javascript -->
<script src="/hplus/js/plugins/layer/layer.min.js"></script>
<!-- Peity -->
<script src="/hplus/js/andy.js"></script>
<script>
    $(function(){
        let options={
            url:'/system/userRole/data',
            sortable:false,
            columns:[
                {
                    checkbox : true,
                    align : 'center'
                },
                {
                    field:'userId',
                    title:'用户ID',
                    align: 'center',
                    halign: 'center',
                    sortable:true
                },
                {
                    field:'roleId',
                    title:'角色ID',
                    align: 'center',
                    halign: 'center',
                    sortable:true
                },
                {
                    title:'操作',
                    width:100,
                    align: 'center',
                    halign: 'center',
                    formatter:function (value,row,index){
                        let actions=[];
                        actions.push("<a href='javascript:void(0)' onclick=\"edit('编辑用户和角色关联表','container','"+row.userId+"')\" title=\"点击编辑用户和角色关联表\"><i class=\"glyphicon glyphicon-edit\" aria-hidden=\"true\"></i></a>&nbsp;&nbsp;");
                        actions.push("<a href='javascript:void(0)' title='点击删除用户和角色关联表' onclick=\"deleteById('"+row.userId+"')\"><i class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></i></a>&nbsp;&nbsp;");

                        return actions.join("");
                    }
                }
            ]
        }
        $.table.init(options);
    })
</script>
<!-- jQuery Validation plugin javascript-->
<script src="/hplus/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/hplus/js/plugins/validate/messages_zh.min.js"></script>
<script src="/webjars/vue/2.6.14/vue.min.js"></script>
<script>
    var vm = new Vue({
        el: "#layerForm",
        data:{
            entity:{},
            isShow: false
        },
        methods:{
            submitHandler:function () {
                alert(JSON.stringify(this.user))
            }
        }
    });
    function edit(title,el,id){
        vm.entity={};
        $.operate.get('/system/userRole/info/'+id,function(ret){
            vm.entity=ret.data;
            $.modal.openWin('编辑部门表','layerForm');
        })
    }
    function edits(title,el){
        let rows =$('#dataTable').bootstrapTable('getSelections');
        if(rows.length!=1){
            layer.msg('请选择需要修改的数据');
            return;
        }

        vm.entity={};
        $.operate.get('/system/userRole/info/'+rows[0].userId,function(ret){
            vm.entity=ret.data;
            $.modal.openWin('编辑部门表','layerForm');
        })
    }
    function add(title,el){
        vm.entity={};
        $.modal.openWin('新增部门表','layerForm');
    }
    function save(){
        if($("#mForm").valid()){
            $.operate.saveWin('/system/userRole/save',JSON.stringify(vm.entity),function(ret){

            });
        }
    }
    function deletes(){
        let rows =$('#dataTable').bootstrapTable('getSelections');
        if(rows.length==0){
            layer.msg('请选择需要删除的数据');
            return;
        }
        let ids = new Array();
        for(let i=0;i<rows.length;i++){
            let row = rows[i];
            ids.push(row.userId);
        }
        layer.confirm('确定删除选中的'+rows.length+'个数据吗？',function(){
            $.operate.delete('/system/userRole/delete',{ids:ids})
        });
    }
    function deleteById(id){
        layer.confirm('确定删除吗？',function(){
            $.operate.delete('/system/userRole/delete/'+id,'');
        });

    }
    $(function(){
        var icon = "<i class='fa fa-times-circle'></i> ";
        formValidate = $("#mForm").validate({
            rules:{
                userId: "required" , 
                roleId: "required" 
            },
            messages:{
                userId: icon + "必填" , 
                roleId: icon + "必填" 
            }
        })
    })
</script>

<script>

</script>
</html>
